#include <iostream>
#include <vector>
#include <unistd.h>
#include "thread.hpp"

using namespace ThreadModle;

void threadRointe(const std::string &name)
{
    while (true)
    {
        std::cout << name << " is running..." << std::endl;
        sleep(1);
    }
}

int main()
{
    //创建多线程
    std::vector<Thread> threads;
    
    for (int i = 0; i < 10; i++)
    {
        std::string name = "Thread-" + std::to_string(i + 1);
        Thread t(name, threadRointe);
        threads.emplace_back(t);
    }
    std::cout << std::endl;
    sleep(2);
    for (auto &thread : threads)
    {
        thread.Start();
    }

    sleep(10);
    std::cout << std::endl;
    
    for (auto &thread : threads)
    {
        thread.Stop();
    }
    std::cout << std::endl;
    sleep(2);
    for (auto &thread : threads)
    {
        thread.join();
    }
    std::cout << std::endl;

    /* 
    //创建单线程
    Thread t("Thread_1", threadRointe);
    t.Start();
    std::cout << "status: " << t.Status() << std::endl;

    sleep(3);

    t.Stop();
    std::cout << "status: " << t.Status() << std::endl;

    sleep(3);

    t.join(); */

    return 0;
}